﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace canyinguanlixitong
{
    public partial class lianhejiezhang : Form
    {
        public lianhejiezhang()
        {
            InitializeComponent();
        }
        public string jia="0";
        public string cz;
        private void lianhejiezhang_Load(object sender, EventArgs e)
        {
            textBox1.Text = jia;
            textBox2.Text = jia;
        }

        private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBox1.Checked==true)
            {
                textBox3.ReadOnly = false;
                if (Convert.ToDouble(textBox1.Text)==Convert.ToDouble(textBox2.Text))
                {
                    textBox3.Text = Convert.ToString(Convert.ToDouble(textBox1.Text));
                }
                else
                {
                    textBox3.Text = Convert.ToString(Convert.ToDouble(textBox2.Text));
                }


            }
            else
            {
                textBox3.ReadOnly = true;
                textBox2.Text = textBox3.Text.Trim();
                textBox3.Text = "0";
                
            }
        }

        private void checkBox2_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBox2.Checked == true)
            {
                textBox4.ReadOnly = false;
                if (Convert.ToDouble(textBox1.Text) == Convert.ToDouble(textBox2.Text))
                {
                    textBox4.Text = Convert.ToString(Convert.ToDouble(textBox1.Text));
                }
                else
                {
                    textBox4.Text = Convert.ToString(Convert.ToDouble(textBox2.Text));
                }

            }
            else
            {
                textBox4.ReadOnly = true;
                textBox2.Text = textBox4.Text.Trim();
                textBox4.Text = "0";
                
            }
        }

        private void checkBox3_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBox3.Checked == true)
            {
                textBox5.ReadOnly = false;
                textBox6.ReadOnly = false;
                if (Convert.ToDouble(textBox1.Text) == Convert.ToDouble(textBox2.Text))
                {
                    textBox5.Text = Convert.ToString(Convert.ToDouble(textBox1.Text));
                }
                else
                {
                    textBox5.Text = Convert.ToString( Convert.ToDouble(textBox2.Text));
                }

            }
            else
            {
                textBox5.ReadOnly = true;
                textBox6.ReadOnly = true;
                textBox2.Text = textBox5.Text.Trim();
                textBox5.Text = "0";
                
            }
        }

        private void textBox3_TextChanged(object sender, EventArgs e)
        {
            if (textBox3.Text.Trim()==string.Empty)
            {
                textBox3.Text = Convert.ToString(0);
                textBox2.Text = Convert.ToString(Convert.ToDouble(textBox1.Text) - Convert.ToDouble(0) - Convert.ToDouble(textBox4.Text) - Convert.ToDouble(textBox5.Text));
            }
            else
            {
                textBox2.Text = Convert.ToString(Convert.ToDouble(textBox1.Text) - Convert.ToDouble(textBox3.Text) - Convert.ToDouble(textBox4.Text) - Convert.ToDouble(textBox5.Text));
            }
            
        }

        private void textBox4_TextChanged(object sender, EventArgs e)
        {
            if (textBox4.Text.Trim()==(string.Empty))
            {
                textBox4.Text = Convert.ToString(0);
                textBox2.Text = Convert.ToString(Convert.ToDouble(textBox1.Text) - Convert.ToDouble(textBox3.Text) - Convert.ToDouble(0) - Convert.ToDouble(textBox5.Text));
            }
            else
            {
                textBox2.Text = Convert.ToString(Convert.ToDouble(textBox1.Text) - Convert.ToDouble(textBox3.Text) - Convert.ToDouble(textBox4.Text) - Convert.ToDouble(textBox5.Text));
            }
        }

        private void textBox5_TextChanged(object sender, EventArgs e)
        {
            if (textBox5.Text.Trim()==string.Empty)
            {
                textBox5.Text = Convert.ToString(0);
                textBox2.Text = Convert.ToString(Convert.ToDouble(textBox1.Text) - Convert.ToDouble(textBox3.Text) - Convert.ToDouble(textBox4.Text) - Convert.ToDouble(0));
            }
            else
            {
                textBox2.Text = Convert.ToString(Convert.ToDouble(textBox1.Text) - Convert.ToDouble(textBox3.Text) - Convert.ToDouble(textBox4.Text) - Convert.ToDouble(textBox5.Text));
            }
            
        }

        private void button1_Click(object sender, EventArgs e)
        {
            bingkejiezhang bin = new bingkejiezhang();
            if (textBox2.Text.Trim().Equals("0"))
            {
                jia = textBox2.Text.Trim();
                bin.Activate();
                this.Close();
            }
            else
            {
                jia = textBox2.Text.Trim();
                MessageBox.Show("金额不足结账失败");
            }
            
        }
    }
}
